import cv2
import numpy as np
import os
import shutil
from libs.utils import isBlack
# 读取图像
def read_image(file_path):
    with open(file_path, 'rb') as f:
        data = f.read()
    image = cv2.imdecode(np.frombuffer(data, np.uint8), cv2.IMREAD_COLOR)
    return image

# 保存图像
def write_image(file_path, image):
    ext = os.path.splitext(file_path)[1]
    _, buf = cv2.imencode(ext, image)
    with open(file_path, 'wb') as f:
        f.write(buf)

dir = os.path.join(
    os.path.dirname(__file__), '..','归档','针柱之洞','正常')
for root,dirs,files in os.walk(dir):
    for file in files:
        if file.endswith('png'):
            path = os.path.join(root,file)
            img = read_image(path)
            cv2.imshow('1',img)
            key = cv2.waitKey(0)
            if key == 49:
                shutil.copy(path,os.path.join(os.path.dirname(path),'..','怪物','其他',file))
                os.unlink(path)
                print(os.path.join(os.path.dirname(path),'..','怪物','其他',file))
            if key == 50:
                shutil.copy(path,os.path.join(os.path.dirname(path),'..','怪物','一只猫',file))
                os.unlink(path)
                print(os.path.join(os.path.dirname(path),'..','怪物','一只猫',file))
            if key == 51:
                os.unlink(path)
            cv2.destroyAllWindows()
